#include<iostream>
#include<fstream>
#include<func.h>
#include<string>
using std::endl;
using std::cout;
using std::ifstream;
using std::cerr;
using std::string;

//beginning is ok beginning
void reFind(const char* pstr,const char*findpstr){
    string contnet(pstr);
    int num = 0;
    int count = 0;
    while(1){
        size_t pos = contnet.find(findpstr,num); //这里的0应该要更新，是下一次的值
        if(pos == std::string::npos){
            cout<<"not found\n";
            break;
        }
        else{
            cout<<count<<endl;
            count++;
            cout<<pos<<endl;
            //cout<<"found :"<<contnet.substr(pos)<<endl;
            num = pos + strlen(findpstr);
        }
    }
}
int main(int argc,char *argv[])
{

    //ARGS_CHECK(argc,2);
    //./Record The_Holy_Bibile.txt

    string filename = "The_Holy_Bible.txt";
    ifstream ifs(filename,std::ios::ate); //从文件末尾打开
    if(!ifs){
        cerr<<"ifs open is fail!"<<endl;
        return -1;
    }
    //获取长度
    long length = ifs.tellg();//获取文件长度
    //cout<<length<<endl;
    //打印字符串
    char*pdata = new char[length+1]();
    //需要将游标放到开头
    ifs.seekg(0,std::ios::beg);
    ifs.read(pdata,length);
#if 0
    //string content("beginning is ok");
    //size_t n = content.find("is",0);
    //if(n == std::string::npos){
    //    cout<<"not found\n";
    //}
    //else{
        //找到后,移动游标到后beginning 的后面，然后继续读
    //    size_t num = n + strlen("beginning");
    //    cout<<n<<endl;
    //    cout<<num<<endl;
    //    cout<<"found :"<<content.substr(n,2)<<'\n'; // 第2个参数 填写字符串的参数
    //}
    //ifs.close();
#endif
    reFind(pdata,"firmament");
    return 0;
}